package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: thoughtworker
 * Date: 10/9/13
 * Time: 11:16 AM
 * To change this template use File | Settings | File Templates.
 */
public class Menu {

    private Collection<String> options;
    private Library library;
    private BufferedReader reader;

    public Menu(Library library, BufferedReader reader) {
        this.library = library;
        this.reader = reader;
        this.options = menuRepository.buildMenu();
    }

    public void printMenuOptions(PrintStream printer) {
        for(String option : options) {
            printer.println(option);
        }
    }

    public void checkMenuOption(String userInput, PrintStream printer) {
        if (options.contains(userInput)) {
            printer.println("Valid Option!!");
        } else {
            printer.println("Select a valid option!!");
        }
    }

    public void respondToUserInput(String input) throws IOException {
        if (input.equals("Reserve a book")) {
            library.reserveBook(reader.readLine());
        } else {
            library.printBookTitle(System.out);
        }
    }
}
